<!DOCTYPE html>
<html lang="zh-CN">
<head>
 
    <meta charset="utf-8" />
    <title>云平台管理系统-时空电动</title>
    <meta content="width=device-width, height=device-height, initial-scale=1.0" name="viewport" />
    <meta content="" name="description" />
    <meta content="" name="author" />
    <link rel="shortcut icon" href="${base}/static/img/icon_btkj.png"> 

 
<#include "bases/global_style.ftl">
<#include "bases/global_js.ftl">
<#include "bases/combo.ftl">
 
     <#--<link rel="stylesheet" href="<@spring.url '/static/css/main.min.css'></@spring.url>"> -->
 
   
    <script>
        var curent_page=${currentpage};
        function getOptionsFromForm()
        {
            var opt = {callback: pageselectCallback};
            opt['items_per_page'] = 15;
            opt['num_display_entries'] = 10;
            opt['num'] = 2;
            opt['prev_text'] = '上一页';
            opt['next_text'] = '下一页';
            opt['current_page'] = curent_page;
            return opt;
        }

        function doDeleteTableRow(id)
        {
            if(confirm('您确定要删除该管理员吗？'))
            {

                $("#postactionorder").val("deleteUser");

                $("#postaction1").val("delete");

                $("#postarg").val(id);
                $("#searchform").submit();
            }
            return true;
        }

        function doResetPW(id) 
        {
            if(confirm('您确定要重置该管理员密码？'))
            {
                $("#postactionorder").val("resetPW");
                $("#postaction1").val("resetPW");
                $("#postarg").val(id);
                $("#searchform").submit();
            }
            return true;
        }

        jQuery(document).ready(function()
        {
            var optInit = getOptionsFromForm();
            $("#Pagination").pagination(${totalRecord}, optInit);
            App.init();
            FormComponents.init();
        });

        function pageselectCallback(page_index, jq)
        {
            if (curent_page != page_index)
            {
                $("#currentpage").val(page_index);
                $("#searchform").submit();
                return true;
            }
        }

        function doTableSort(ID)
        {
            $("#postsortfield").val(ID);
            $("#currentpage").val(0);
            $("#searchform").submit();
        }
        
        
        function addEntity() 
        {
            var addUserName=document.getElementById("addUserName").value;
            var addPassword=document.getElementById("addPassword").value;
            var addPassword2=document.getElementById("addPassword2").value;
            var addEntityName=document.getElementById("addEntityName").value;
            var addEntityId =$('#addEntityName option:selected').val();
            var addRole=document.getElementById("addRole").value;
            var addPhone=document.getElementById("addPhone").value;
            var addEmail=document.getElementById("addEmail").value;

            var addRole=document.getElementById("addRole").value;
            var addUserSex =$('#addUserSex option:selected').val();
            var count = true;

            resetLabel();
            if (addUserName == null || addUserName == "") {
                document.getElementById("addUserName").style.borderColor = "#FF0000";
              // document.getElementById("addUserNameIsNull").value="用户名不能为空！";
                //document.getElementById("addUserNameIsNull").showPopup();
                //$('#site_statistics_loading').hide();

                count=false;
            }else {
                var z = /^[0-9a-zA-Z_]+$/;
                if(!z.test(addUserName)){
                    count = false;
                    alert("用户名只能是字母、数字和下划线！");

                }

            }
            if (addPassword == null || addPassword == "") {
                document.getElementById("addPassword").style.borderColor = "#FF0000";
                count=false;
            }
            if (addPassword2 == null || addPassword2 == "") {
                document.getElementById("addPassword2").style.borderColor = "#FF0000";
                count=false;
            }

            if (addEntityName == null || addEntityName == "") {
                document.getElementById("addEntityName").style.borderColor = "#FF0000";

                count=false;
            }
            if (addPhone == null || addPhone == "") {
                document.getElementById("addPhone").style.borderColor = "#FF0000";
                count=false;
            }
            if (addEmail == null || addEmail == "") {
                document.getElementById("addEmail").style.borderColor = "#FF0000";
                count=false;
            }else{
                var z = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;//简单的邮箱匹配的正则表达式
                if(!z.test(addEmail)){
                    count=false;
                    alert("邮箱不合法！");
                }
            }

            //核对两次密码是否一致
            if(addPassword != addPassword2 && addPassword!=null &&addPassword!=""&&
                addPassword2!=null &&addPassword2!=""){
                document.getElementById("addPassword").style.borderColor = "#FF0000";
                document.getElementById("addPassword2").style.borderColor = "#FF0000";
                count=false;
                alert("两次密码输入不一致！");
            }
            if (count)
            {
                //调用函数判断密码是否合法，4字符以上，只能是数字和字母
                var z = /^[0-9a-zA-Z]+$/;
                if(z.test(addPassword) && addPassword.length>=4)
                {
                var a ;
                var nowtime = new Date();
                var strtemp = ""+nowtime.getHours()+nowtime.getMinutes()+nowtime.getSeconds()+nowtime.getMilliseconds();
                a=strtemp;
                $.getJSON("{${base}/add_adminuser_in_admin_user_manage_ftl/" + a+
                                "?addUserName="+addUserName+
                                "&addPassword="+addPassword+
                                "&addEntityId="+addEntityId+
                                "&addEntityName="+addEntityName+
                                "&addRole="+addRole+
                                "&addUserSex="+addUserSex+
                                "&addPhone="+addPhone+
                                "&addEmail="+addEmail
                        ,
                        function(data)
                        {
                            if(data ==1) {
                                alert("添加成功！");
                                $("#addForm").submit();
                            }
                            else if(data == -2)
                                alert("用户名已存在！");
                            else if(data ==-1)
                                alert("未知错误！");
                        });
                }else{
                    alert("密码必须是不小于4个字符的字母和数字");
                }
            }
        }
        
         
        function showEditDiv(id, role) 
        {
        	edit_user_id = id;
            var objS = document.getElementById("editRole");
            objS.value=role;

            showEditPopup("editDiv");
        }
        
        function showEditPopup(div) 
        {//弹出层
            var backDiv = document.getElementById("backDiv");
            backDiv.style.top = "0%";//设置弹出层距离上边界的距离
            backDiv.style.left = "0%";//设置弹出层距离左边界的距离
            backDiv.style.width = "100%";//设置弹出层的宽度
            backDiv.style.height = "100%";//设置弹出层的高度
            backDiv.style.visibility = "visible";

            var realDiv = document.getElementById(div);
            realDiv.style.top = "30%";//设置弹出层距离上边界的距离
            realDiv.style.left = "30%";//设置弹出层距离左边界的距离
            realDiv.style.width = "40%";//设置弹出层的宽度
            realDiv.style.height = "auto";//设置弹出层的高度
            realDiv.style.visibility = "visible";
        }
        	     
        	     
        function updateTable() 
        {
            var role=document.getElementById("editRole").value;
            var count = 0;
            if (role == null || role == "") {
                document.getElementById("role").style.borderColor = "#FF0000";
            } else {
                count ++;
            }

            $("#postactionorder2").val("update");
            $("#postarg2").val(edit_user_id);

            if (count == 1) { $("#editForm").submit(); }
        }
        

        function resetLabel() 
        {
            document.getElementById("addUserName").style.borderColor = "#BBB";
            document.getElementById("addEntityName").style.borderColor = "#BBB";
            document.getElementById("addPhone").style.borderColor = "#BBB";
            document.getElementById("addEmail").style.borderColor = "#BBB";
        }

        function showPopup() 
        {//弹出层
            var backDiv = document.getElementById("backDiv");
            backDiv.style.top = "0%";//设置弹出层距离上边界的距离
            backDiv.style.left = "0%";//设置弹出层距离左边界的距离
            backDiv.style.width = "100%";//设置弹出层的宽度
            backDiv.style.height = "100%";//设置弹出层的高度
            backDiv.style.visibility = "visible";

            var realDiv = document.getElementById("realDiv");
            realDiv.style.top = "30%";//设置弹出层距离上边界的距离
            realDiv.style.left = "30%";//设置弹出层距离左边界的距离
            realDiv.style.width = "40%";//设置弹出层的宽度
            realDiv.style.height = "auto";//设置弹出层的高度
            realDiv.style.visibility = "visible";
        }
        
        function hideEditTable() 
        {//关闭层
            $("#editRole").val(null);
            resetEditLabel();

            var backDiv = document.getElementById("backDiv");
            backDiv.style.visibility = "hidden";

            var realDiv = document.getElementById("editDiv");
            realDiv.style.visibility = "hidden";
        }

        function resetEditLabel() 
        {
            document.getElementById("editRole").style.borderColor = "#BBB";
        }
        
        function hidePopup() 
        {//关闭层
        /*    $("#addUserName").val(null);
            $("#addEntityName").val(null);
            $("#addPhone").val(null);
            $("#addEmail").val(null);*/
            $("#addPassword").val(null);
            $("#addPassword2").val(null);
            resetLabel();
            var backDiv = document.getElementById("backDiv");
            backDiv.style.visibility = "hidden";

            var realDiv = document.getElementById("realDiv");
            realDiv.style.visibility = "hidden";
        }
        
        function allDivHide() 
        {
            hidePopup();
            hideEditTable();
        }

    </script>
    <style type="text/css">
        h2.pos_left
        {
            position:relative;
            left:-20px
        }
        h2.pos_right
        {
            position:absolute;
            text-align: left;
            left:0px;
            top:0px;
            z-index:-1
        }
    </style>
</head>

<body class="page-header-fixed">

<div id="backDiv" onclick="allDivHide()" style="position: absolute;visibility: hidden;position:fixed;overflow: hidden;solid: #000000;background-color: #000000;padding: 1px;z-index: 99;filter:alpha(opacity=50);opacity: 0.5;"></div>

<div id="realDiv" class="row-fluid" style="position: absolute;visibility: hidden;overflow: hidden;padding: 1px;z-index: 100;background-color: #FFFFFF;">
    <div class="span12">
        <div class="portlet box green" style="padding: 0px;margin:0px;">
            <div class="portlet-title">
                <div class="caption"><i class="icon-edit"></i>添加管理员</div>
                <a href="javascript:allDivHide();" class="remove"></a>
            </div>

            <div class="portlet-body flip-scroll">
                <form id="addForm" action="<@spring.url '/admin_user_manage'></@spring.url>" method="POST">
                    <table class="table-bordered table-striped table-condensed flip-content">
                        <tbody role="alert" aria-live="polite" aria-relevant="all">
                        <tr class="even">
                            <td style="text-align: right;">用户名</td>
                            <td class="even">
                                   <input class="m-wrap span8" style="margin-top: 10px" type="text" id="addUserName" name="addUserName" value="${addUserName}" placeholder="请输入用户名" />
                            </td>
                        </tr>
                        <tr class="even">
                            <td style="text-align: right;">密码</td>
                            <td class="center">
                                <input class="m-wrap span8" style="margin-top: 10px" type="password" id="addPassword" name="addPassword" value="${addPassword}" placeholder="请输入密码"/>
                            </td>
                        </tr>
                        <tr class="even">
                            <td style="text-align: right;">确认密码</td>
                            <td class="center">
                                <input class="m-wrap span8" style="margin-top: 10px" type="password" id="addPassword2" name="addPassword2" value="${addPassword2}" placeholder="请再次输入密码"/>
                            </td>
                        </tr>
                        <tr class="even">
                            <td style="text-align: right;">所属单位</td>
                            <td class="center">
                                <select id="addEntityName" name="addEntityName" class="span8 small m-wrap" value="${addEntityName}" style="margin-top: 10px" placeholder="">
                                <#list myulist as aus> 
                                    <option value="${aus.getId()}"><#if aus.getName()?exists>${aus.getName()}</#if></option>
                                </#list>
                                </select>
                            </td>
                        </tr>

                        <tr class="even">
                            <td style="text-align: right;">角色</td>
                            <td class="center">
                                <select id="addRole" name="addRole" class="span8 small m-wrap" value="${addRole}" style="margin-top: 10px" placeholder="">
                                <#if rolelist?exists>
                                <#list rolelist as rl>
                                    <option value="${rl.getName()}" <#if addRole=="${rl.getName()}">selected="selected"</#if>><#if rl.getName()?exists>${rl.getName()}</#if></option>
                                </#list>
                                </#if>
                                </select>
                            </td>
                        </tr>

                        <tr class="even">
                            <td style="text-align: right;">性别</td>
                            <td class="center">
                                <select id="addUserSex" name="addUserSex" class="span8 small m-wrap" value="${addUserSex}" style="margin-top: 10px" placeholder="">
                                    <option value="male" <#if addUserSex=="male">selected="selected"</#if>>男</option>
                                    <option value="female" <#if addUserSex=="female">selected="selected"</#if>>女</option>
                                </select>
                            </td>
                        </tr>
                        
                        
                        <tr class="odd">
                            <td style="text-align: right;">联系方式</td>
                            <td class="center">
                                <input class="m-wrap span8" style="margin-top: 10px" type="text" id="addPhone" name="addPhone" value="${addPhone}" placeholder="请输入联系方式" />
                            </td>
                        </tr>
                        
                        <tr class="odd">
                            <td style="text-align: right;">邮箱</td>
                            <td class="center">
                                <input class="m-wrap span8" style="margin-top: 10px" type="text" id="addEmail" name="addEmail" value="${addEmail}" placeholder="请输入邮箱"/>
                            </td>
                        </tr>
                        </tbody>
                    </table>
                    </br>
                    <div class="controls controls-row" style="text-align: right;">
                        <input type="button" value="提交" class="btn green" onclick="addEntity()"/>
                        <input type="button" value="取消" class="btn green" onclick="allDivHide()" />
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>

<div id="editDiv" class="row-fluid" style="position: absolute;visibility: hidden;overflow: hidden;padding: 1px;z-index: 100;background-color: #FFFFFF;">
    <div class="span12">
        <div class="portlet box green" style="margin: -1px;">
            <div class="portlet-title">
                <div class="caption"><i class="icon-edit"></i>编辑管理人员</div>
                <a href="javascript:hideEditTable();" class="remove"></a>
            </div>

            <div class="portlet-body flip-scroll">
                <form id="editForm" action="<@spring.url '/admin_user_manage'></@spring.url>" method="POST">
                    <table id="editTable" class="table-bordered table-striped table-condensed flip-content">
                        <input  type="hidden" id="postactionorder2" name="postactionorder" />
                        <input  type="hidden" id="postarg2" name="postarg" />
                        <tbody role="alert" aria-live="polite" aria-relevant="all">
                        <tr class="even">
                            <td style="text-align: right;">角色</td>
                            <td class="center">
                                <select id="editRole" name="editRole" class="span8 small m-wrap" style="margin-top: 10px" placeholder="">
                                <#list rolelist as rl>
                                    <option value="${rl.getName()}" ><#if rl.getName()?exists>${rl.getName()}</#if></option>
                                </#list>
                                </select>
                            </td>
                        </tr>
                        </tbody>
                    </table>
                    
                    </br>
                    <div class="controls controls-row" style="text-align: right;">
                        <input type="button" value="提交" class="btn green" onclick="updateTable()"/>
                        <input type="button" value="取消" class="btn green" onclick="hideEditTable()" />
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>


<div class="page-container row-fluid">

<#include "bases/sidebar.ftl">
<#include "bases/navhead.ftl">

    <div class="page-content">
        <div class="container-fluid">
            <div class="row-fluid">
                <div class="span12">
                    <br/>
                    <ul class="breadcrumb">
                        <li>
                            <i class="icon-home"></i>
                            <a href="${base}/index">首页</a>
                            <i class="icon-angle-right"></i>
                        </li>
                        <li>
                            <a href="#">系统管理</a>
                            <i class="icon-angle-right"></i>
                        </li>
                        <li><a href="#">管理人员</a></li>
                    </ul>
                </div>
            </div>
            <div class="row-fluid">
                <div class="span12">
                    <div class="portlet box green">
                        <div class="portlet-title">
                            <div class="caption"><i class="icon-cogs"></i>管理人员列表</div>
                        </div>
                        <div class="portlet-body flip-scroll">
                            <form id="searchform" action="${base}/admin_user_manage" method="POST">
                               
                                <div class="controls controls-row">
                                        <label id="insertdlg" class="labelcss">手机号：</label>
                                        <input id="username" name="username" type="text" class="input-small" value="${username}"/>
                                        
                                        <label id="insertdlg" class="labelcss">车牌号：</label>
                                        <input id="username" name="username" type="text" class="input-small" value="${username}"/>
                                        
                                        <label id="insertdlg" class="labelcss">所属公司：</label>
                                        <@combo selectId="company" selectName="company" items=["mouse", "elephant", "python"]/> 
                                        
                                        <label id="insertdlg" class="labelcss">车型：</label>
                                        <@combo selectId="company" selectName="company" items=["mouse", "elephant", "python"]/> 
                                
                                         <button type="submit" class="control-btn btn blue" style="margin-right: 5px;"> 搜索</button>
                                </div>
                                
                               <div class="controls controls-row">
 
                                    <button id="sample_editable_1_new" type="button" class="btn green" onclick="showPopup()">新增用户</button>
                                    <button id="sample_editable_1_new" type="button" class="btn green" onclick="showPopup()">批量匹配资费</button>
                                    <button id="sample_editable_1_new" type="button" class="btn green" onclick="showPopup()">批量发放活动</button>
                                  
                                    <input  type="hidden" id="currentpage" name="page" value="0" />
                                    <input  type="hidden" id="postsortfield" name="sortfield" value="${sortfield}" />
                                    <input  type="hidden" id="postactionorder" name="postactionorder" />
                                    <input  type="hidden" id="postaction1" name="postaction" />
                                    <input  type="hidden" id="postarg" name="postarg" />
                                </div>
                               
                                <table  class="table table-bordered table-hover">
                                    <thead class="flip-content">
                                    <tr>
                                        <th onclick="javascript:doTableSort('username')">用户名</th>
                                        <th>所属单位</th>
                                        <th>性别</th>
                                        <th onclick="javascript:doTableSort('start_time')">联系方式</th>
                                        <th onclick="javascript:doTableSort('end_time')">邮箱</th>
                                        <th>创建时间</th>
                                        <th>上次登录时间</th>
                                        <th>登录次数</th>
                                        <th style="width: 150px">操作</th>
                                    </tr>
                                    </thead>
                                    <tbody>
                                    <#list admin_users as aus>
                                    <tr>
                                        <td style="text-align: center;"><#if aus.getUsername()?exists>${aus.getUsername()}</#if></td>
                                        <td style="text-align: center;"><#if aus.getEntityname()?exists>${aus.getEntityname()}</#if></td>
                                        <td style="text-align: center;">
                                            <#if aus.getSex()?exists>
                                                <#if aus.getSex() == "male">
                                                                                                                                                                        男
                                                <#else>
                                                                                                                                                                       女
                                                </#if>
                                            </#if>
                                        </td>
                                        <td style="text-align: center;"><#if aus.getPhone()?exists>${aus.getPhone()}</#if></td>
                                        <td style="text-align: center;"><#if aus.getEmail()?exists>${aus.getEmail()}</#if></td>
                                        <td style="text-align: center;"><#if aus.getCreatedate()?exists>${dataDisplayUtil.toDateTime(aus.getCreatedate())}</#if></td>
                                        <td style="text-align: center;"><#if aus.getLastlogin()?exists> ${dataDisplayUtil.toDateTime(aus.getLastlogin())} </#if></td>
                                        <td style="text-align: center;"><#if aus.getLogintimes()?exists> ${aus.getLogintimes()} </#if></td>
                                        <td style="text-align: center;">
                                            <a onclick="doResetPW('${aus.getId()}');"
                                               class="btn btn-success btn-grad">重置密码</a>
                                            <#if aus.getUsername()?exists &&user_info.getUsername()?exists && aus.getUsername()!=user_info.getUsername()>
                                        		<#if role?exists>
                                        	<a id="editButton" onclick="showEditDiv('${aus.getId()}', '${dataDisplayUtil.getRoleNameByAdminId(aus.getId())}');"
                                               class="btn btn-success btn-grad">编辑</a>
												</#if>
                                            <a onclick="doDeleteTableRow('${aus.getId()}');"
                                               class="btn btn-danger btn-grad">删除</a>
                                            </#if>
                                        </td>
                                    </tr>
                                    </#list>
                                    </tbody>
                                </table>
                                <div class="controls controls-row">
                                    <div id="Pagination" class="pagination"></div>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
</div>
</body>
</html>

 
